<?php

class SituacaoController extends Zend_Controller_Action
{

    public function init()
    {
        
    }

    public function indexAction()
    {
        //echo '<pre>';var_dump($_SESSION['user']->getFullName());die;
        $situacao = new Application_Model_DbTable_Situacao();
		$this->view->situacao = $situacao->fetchAll();
    }

    public function addAction()
    {
    	$form = new Application_Form_Situacao();
        $form->submit->setLabel('Gravar');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $situacao = $form->getValue('situacao');
                $situacoes = new Application_Model_DbTable_Situacao();
                $situacoes->addSituacao($situacao);
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        }
    }

    public function editAction()
    {
        $form = new Application_Form_Situacao();
        $form->submit->setLabel('Salvar');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = (int) $form->getValue('idtipo_situacao');
                $situacaotipo = $form->getValue('situacao');
                $situacao = new Application_Model_DbTable_Situacao();
                $situacao->updateSituacao($id, $situacaotipo);
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            if ($id > 0) {
                $situacao = new Application_Model_DbTable_Situacao();
                $form->populate($situacao->getSituacao($id));
            }
        }
    }

    public function deleteAction()
    {
    	if ($this->getRequest()->isPost()) {
            $del = $this->getRequest()->getPost('del');
            if ($del == 'Sim') {
                $id = $this->getRequest()->getPost('id');
                $situacao = new Application_Model_DbTable_Situacao();
                $situacao->deleteSituacao($id);
            }
            $this->_helper->redirector('index');
        } else {
            $id = $this->_getParam('id', 0);
            $situacao = new Application_Model_DbTable_Situacao();
            $this->view->situacao = $situacao->getSituacao($id);
        }
    }


}







